<include file="Public/header" />
<style type="text/css">
    #saveBtn,#finalBtn{min-width:120px;}
    #two_cell,.lib-edit .preview .cell{border-left:0;}
    .unique_div h4{padding-top:20px;}
</style>
<div class="comm-top">
	<include file="Wechat/reply_nav" act_nav="reply_single"/>
</div>
<div class="lib-edit">
    <div class="header" style="border:0;border-bottom:1px solid #dbdbdb;">
        <a href="javascript:history.back('-1')"><i class="icons icons-back"></i> 单图文内容编辑</a>
    </div>
    <div class="content">
        <div class="preview" style="margin-right:-5px;">
            <div id="one_cell" class="cell" style="border-left:0;">
                <div class="cover">
                    <h3 style="background:none;background-color:#111;filter:alpha(opacity=30);opacity:0.3;">{$item.title|default='标题'}</h3>
                    <div class="img-default">
                        <if condition="$item.pic">
                            <img src="{$item.pic}" style="width:246px;height:136px;" />
                        <else/>
                            <div style="width:246px;height:136px;font-size:22px;padding-top:40px;">封面图片</div>
                        </if>
                    </div>
                </div>
            </div>
        </div>
        <div class="editor" style="width:590px;">
            <form id="memberform" onsubmit="return false;">
            	<input name="info[id]" type="hidden" value="{$item.id}"/>
            	<input name="info[customer_id]" type="hidden" value="{$customer.id}"/>
            	<input name="info[type]" type="hidden" value="2"/>
                <div class="cell" id="one_one">
                    <div class="form-rule" role="form">
                        <div class="form-group">
                            <label>关键词<strong class="c-red">*</strong><span class="c-gray">（注:多个规则对应一条内容用逗号分隔。如：help ,帮助）</span></label>
                            <input name="info[keyword]" value="{$item.keyword}" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="form-rule form-rule-add" role="form">
                    <div class='cell'>
                        <div class="form-group">
                            <label>标题</label>
                            <input id="actureTitle" type="text" name="info[title]" value="{$item.title}" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>封面
                                <span class="c-gray">（图片建议尺寸：<i style="color:red;font-style:normal;">540px*300px</i>）</span>
                            </label>
                            <div class="fg-upload" onclick="up_img_fun('{:U('Admin/PicUpload/index')}')">
                            	<input type="hidden" id="info_pic" name="info[pic]" value="{$item.pic}" />
                                <input id="local-image" type="text" readonly class="form-control" style="padding-left:70px;">
                                <a href="javascript:void(0);" class="btn-upload"><i class="icons icons-upload"></i>上传</a>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>内容</label>
                            <textarea id="content" name="info[content]" style="height:160px">{$item.content}</textarea>
                        </div>

                        <div class="form-group">
                            <label>外部链接 <span class="c-gray">(选填)</span></label>
                            <input type="text" class="form-control" name="info[url]" value="{$item.url}">
                        </div>
                    </div>
                </div>
                <div class="cell cell-dark" id='one_state'>
                    <div class="form-rule" role="form">
                        <div class="form-group">
                            <label>状态<strong class="c-red">*</strong> <span class="c-gray"></span></label>
                            <br/>
                            <label><input type="radio" name="info[state]" value='1' {:$item['state']!='2'?'checked': ''} value='1' /> 开放</label>
                            &nbsp;&nbsp;
                            <label><input type="radio" name="info[state]" value='2' {:$item['state']=='2'?'checked': ''} value='2' /> 关闭</label>
                        </div>
                    </div>
                </div>
            </form>
            <div class="opt">
                <a class="btn btn-large btn-success" id="saveBtn" href="javascript:void(0);" onclick="save(this);">保存</a>
            </div>
        </div>
    </div>
</div>
<!-- 上传图片开始 -->	
<link rel="stylesheet" type="text/css" href="__PUBLIC__/upimg/css/upimg.css" />
<script type="text/javascript" src="__PUBLIC__/upimg/upimg.js"></script>
<script type="text/javascript">
/**
 * up_img_fun(up_img_php) 执行上传的函数，微沟通图片上传的改版
 * @param string up_img_php 后台处理图片上传的文件
 * 
 * up_img_notify(img_path) 上传回调函数
 * @param string img_path 返回的图片地址，图片仍放在/data/image_c/下
 */
function up_img_notify(img_path){
    $('#info_pic').val(img_path);
    $('#one_cell .img-default').html('<img src="'+img_path+'" style="width:246px;height:136px;"/>');
}
</script>
<!-- 上传图片结束 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
$(function(){
    //初始化编辑器
    UE.getEditor('content', {
        toolbars: [['source','bold','italic','underline','fontsize','forecolor','backcolor','pasteplain',
        'insertorderedlist','cleardoc','link','simpleupload','emotion','map','inserttable',
        //'insertimage',//多图上传
        ]]
    });
  //标题预览
    $('#actureTitle').keyup(function(){
        $('#one_cell h3').text($(this).val());
    });
});
function save(obj){
    if($("input[name='info[keyword]']").val()==''){
        note_info('请填写关键词',obj,'warn');return;
    }
    if($("input[name='info[title]']").val()==''){
        note_info('请填写标题',obj,'warn');return;
    }
    if($("input[name='info[pic]']").val()==''){
        note_info('请上传图片',obj,'warn');return;
    }
    <!-- if(!isUrl($("input[name='info[url]']").val()) && $.trim($("input[name='info[url]']").val()) != ''){ -->
        <!-- note_info('请填写正确的链接',obj,'warn');return; -->
    <!-- } -->
    if($("textarea[name='info[content]']").val()==''){
        note_info('请填写内容',obj,'warn');return;
    }
    
    $.post("{:U('single_edit')}",$('#memberform').serialize(),function(res){
        if(res.status == 1){
            note_info(res.info,obj);
            setTimeout('window.location.href="{$upPageUrl}"',1200);
        }else{
            note_info(res.info,obj,'warn');
        }
    },'json');
}
//判断URL
function isUrl(str){
    var RegUrl = new RegExp();
    RegUrl.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!RegUrl.test(str)){
        return false;
    }
    return true;
}
</script>
<include file="Public/footer" />